/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Econosim.java
 *
 * Created on May 22, 2009, 3:24:57 PM
 */

package UI;

import MortgageCore.SavingsSim;
import viewer.common.SimView;
import viewer.mortgage.MortgageCorePane;
/**
 *
 * @author Steve Noble
 */
public class Econosim extends javax.swing.JFrame {

    /** Creates new form Econosim */
    public Econosim() {
        initComponents();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        numHHs = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        numBanks = new javax.swing.JSpinner();
        startSim = new javax.swing.JButton();
        logHouseholdDataCheckbox = new javax.swing.JCheckBox();
        adaptiveBankCheckbox = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("EconoSim");
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Mortgage Model"));

        numHHs.setModel(new javax.swing.SpinnerNumberModel(10, 1, 300, 1));

        jLabel2.setText("Number of Households");
        jLabel2.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);

        jLabel3.setText("x 1000");

        jLabel4.setText("Number of Banks");

        numBanks.setModel(new javax.swing.SpinnerNumberModel(15, 1, 100, 1));

        startSim.setText("Create Simulation...");
        startSim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startSimActionPerformed(evt);
            }
        });

        logHouseholdDataCheckbox.setSelected(true);
        logHouseholdDataCheckbox.setText("Log Household and Bank Data");
        logHouseholdDataCheckbox.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        logHouseholdDataCheckbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                logHouseholdDataCheckboxActionPerformed(evt);
            }
        });

        adaptiveBankCheckbox.setText("Adaptive Banks");
        adaptiveBankCheckbox.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
        adaptiveBankCheckbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adaptiveBankCheckboxActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4))
                        .addGap(31, 31, 31))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(adaptiveBankCheckbox)
                            .addComponent(logHouseholdDataCheckbox))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(numHHs)
                    .addComponent(numBanks))
                .addGap(18, 18, 18)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(108, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(299, Short.MAX_VALUE)
                .addComponent(startSim)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(numHHs, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(numBanks, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addComponent(logHouseholdDataCheckbox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(adaptiveBankCheckbox)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
                .addComponent(startSim)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void startSimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startSimActionPerformed
        int hh =((javax.swing.SpinnerNumberModel) numHHs.getModel()).getNumber().intValue();
        int banks =((javax.swing.SpinnerNumberModel) numBanks.getModel()).getNumber().intValue();

        SavingsSim sim = new SavingsSim(1000 * hh, banks, logHouseholdDataCheckbox.isSelected(),
                adaptiveBankCheckbox.isSelected());

        MortgageCorePane mapPane = new MortgageCorePane(sim);

        SimView simView = new SimView(sim, mapPane);

        java.awt.Dimension d = new java.awt.Dimension(1200,1000);

        simView.setSize(d);

        simView.setVisible(true);
    }//GEN-LAST:event_startSimActionPerformed

    private void logHouseholdDataCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logHouseholdDataCheckboxActionPerformed
        ;
}//GEN-LAST:event_logHouseholdDataCheckboxActionPerformed

    private void adaptiveBankCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adaptiveBankCheckboxActionPerformed
        ;
    }//GEN-LAST:event_adaptiveBankCheckboxActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Econosim().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox adaptiveBankCheckbox;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JCheckBox logHouseholdDataCheckbox;
    private javax.swing.JSpinner numBanks;
    private javax.swing.JSpinner numHHs;
    private javax.swing.JButton startSim;
    // End of variables declaration//GEN-END:variables

}
